package org.gikolet.ch2.android.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.List;

import org.gikolet.ch2.data.Board;
import org.gikolet.ch2.data.Category;
import org.gikolet.ch2.io.BoardsReader;
import org.gikolet.util.IOUtils;
import org.gikolet.util.Tuple.Tuple2;

public class LocalKatjushaBoardsReader implements BoardsReader {

	private KatjushaBoardsStreamParser parser;

	public LocalKatjushaBoardsReader(File file, String charsetName)
			throws IllegalCharsetNameException, UnsupportedCharsetException,
			FileNotFoundException, IOException {

		this(file, Charset.forName(charsetName));
	}

	public LocalKatjushaBoardsReader(File file, Charset charset)
			throws FileNotFoundException, IOException {
		this.parser = new KatjushaBoardsStreamParser(new FileInputStream(file),
				charset);
	}

	public long getContentLength() {
		return this.parser.getContentLength();
	}

	public long getReadContentLength() {
		return this.parser.getReadContentLength();
	}

	public Tuple2<Category, List<Board>> read() throws IOException {
		return this.parser.read();
	}

	public void close() throws IOException {
		IOUtils.closeQuietly(this.parser);
	}
}
